package frontend;

import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;

import javax.swing.JButton;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import com.cloudgarden.layout.AnchorConstraint;

import dbmanager.AccountManager;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class SettingsGUI extends javax.swing.JPanel {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JTextField emailField;
	private JLabel emailLabel;
	private JLabel accountLabel;
	private JSeparator jSeparator1;
	private JButton passwordButton;
	private JButton emailButton;
	private JLabel passwordLabel;
	private JPasswordField passwordField;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new SettingsGUI());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public SettingsGUI() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(968, 734));
			this.setLayout(null);
			this.setBackground(new java.awt.Color(255,255,255));
			{
				emailField = new JTextField();
				this.add(emailField);
				emailField.setBounds(694, 69, 154, 22);
			}
			{
				emailLabel = new JLabel();
				this.add(emailLabel);
				emailLabel.setText("E-Mail:");
				emailLabel.setBounds(609, 68, 85, 14);
			}
			{
				passwordField = new JPasswordField();
				this.add(passwordField);
				passwordField.setBounds(694, 115, 154, 20);
			}
			{
				passwordLabel = new JLabel();
				this.add(passwordLabel);
				passwordLabel.setBounds(609, 117, 76, 17);
				passwordLabel.setText("Password:");
			}
			{
				emailButton = new JButton();
				this.add(emailButton);
				emailButton.setText("Change");
				emailButton.setBounds(854, 68, 71, 23);
				emailButton.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						try {
							emailButtonMouseClicked(evt);
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				});
			}
			{
				passwordButton = new JButton();
				this.add(passwordButton);
				passwordButton.setText("Change");
				passwordButton.setBounds(854, 114, 71, 21);
				passwordButton.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						try {
							passwordButtonMouseClicked(evt);
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				});
			}
			{
				jSeparator1 = new JSeparator();
				this.add(jSeparator1);
				jSeparator1.setBounds(591, 12, 20, 710);
				jSeparator1.setOrientation(SwingConstants.VERTICAL);
			}
			{
				accountLabel = new JLabel();
				this.add(accountLabel);
				accountLabel.setText("Account Settings");
				accountLabel.setBounds(621, 12, 197, 31);
				accountLabel.setFont(new java.awt.Font("Bitstream Vera Sans",1,20));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void emailButtonMouseClicked(MouseEvent evt) throws SQLException {
		AccountManager.updateEmail(emailField.getText());
		JOptionPane.showMessageDialog(this, "Your email has been changed.");
	}
	
	private void passwordButtonMouseClicked(MouseEvent evt) throws SQLException {
		AccountManager.updatePassword(new String(passwordField.getPassword()));
		JOptionPane.showMessageDialog(this, "Your password has been changed.");
	}

}
